#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author   : Moty
# @Time     : 2024/1/22 0:06
# @File     : jt808_0001.py
# @Project  : jt808
def parse_0001_general_response(body):
    # 解析0x0001 终端通用应答消息体
    data = {
        "应答流水号": body[0:4],
        "应答 ID": body[4:8],
        "结果": str(parse_0001_result(int(body[8:10], 16)) + '(' + body[8:10]) + ')',
    }
    formatted_data = ""
    for key, value in data.items():
        formatted_data += f"{key}: {value}\n"
    return formatted_data


def parse_0001_result(result_value):
    results = ['成功/确认', '失败', '消息有误', '不支持']
    if 0 <= result_value < len(results):
        return results[result_value]
    else:
        return '未知结果'


__all__ = ['parse_0001_general_response']